package com.vsked.util;

import javax.servlet.http.HttpServletRequest;

public class HtmlProcess {
	
	public static String getXHtmlDeclareForFrameSet(){
		return Symbol.enterSymbol+"<!DOCTYPE html 　　PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" 　　\"http://www.w3. org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">";
	}
	public static String getHtml(String inHtmlContent){
		return Symbol.enterSymbol+"<html>"+inHtmlContent+Symbol.enterSymbol+"</html>";
	}
	public static String getHtmlHead(String inHeadContent){
		return Symbol.enterSymbol+"<head>"+inHeadContent+Symbol.enterSymbol+"</head>";
	}
	public static String getHtmlBody(String inBodyContent){
		return Symbol.enterSymbol+"<body>"+inBodyContent+Symbol.enterSymbol+"</body>";		
	}
	public static String getHtmlHeadBase(String inBasePath){
		return "<base href='"+inBasePath+"'>";
	}
	public static String getMetaEncoding(){
		return Symbol.enterSymbol+"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"> ";
	}
	
	public static String getHtmlHeadTitle(String inHeadTitle){
		return "<title>"+inHeadTitle+"</title>";
	}
	public static String getHtmlHeadMetaContentTypeAndCharset(){
		return getHtmlHeadMeta("Content-Type", "text/html; charset=UTF-8");
	}
	public static String getHtmlHeadMeta(String inEquiv,String inContent){
		return "<meta http-equiv=\""+inEquiv+"\" content=\""+inContent+"\">"; 
	}
	public static String getHtmlHeadIcon(){
		return getHtmlHeadLink("shortcut icon", "/favicon.ico");
	}
	public static String getHtmlHeadLink(String inRel,String inHref){
		return "<link rel=\""+inRel+"\" href=\""+inHref+"\">";
	}
	public static String getHtmlHeadLinkForCss(String inRel,String inHref){
		return "<link rel=\""+inRel+"\"  type=\"text/css\"  href=\""+inHref+"\">";
	}
	public static String getHtmlHeadScript(String inSrc){
		return "<script src=\""+inSrc+"\" type=\"text/javascript\" language=\"javascript\" charset=\"utf-8\"></script>";
	}
	public static String getHtmlHeadScript(String inSrc,String inCharset){
		return "<script src=\""+inSrc+"\" type=\"text/javascript\" language=\"javascript\" charset=\""+inCharset+"\"></script>";
	}
	/***********************************div start*************************************/
	public static String getDiv(String inDivContent){
		return "<div align='center'>"+inDivContent+"</div>";
	}
	public static String getDiv(String inDivId,String inDivContent){
		return "<div id='"+inDivId+"' align='center'>"+inDivContent+"</div>";
	}
	public static String getDiv(String inDivId,String inDivContent,String inClass){
		return "<div id='"+inDivId+"' align='center' "+inClass+">"+inDivContent+"</div>";
	}
	/***********************************Form start*************************************/
	public static String getFormInfo(String inFormId,String inFormAction,String inFormContent){
		return Symbol.enterSymbol+"<form id='"+inFormId+"'  action=\"../"+inFormAction+"\" method='post'>"+inFormContent+Symbol.enterSymbol+"</form>";	
	}
	public static String getInputText(String inType,String inInputName){
		return "<input type='"+inType+"' name='"+inInputName+"' id='"+inInputName+"' value='' />";		
	}
	public static String getInputText(String inInputName){
		return "<input type='text' name='"+inInputName+"' id='"+inInputName+"'  value='' />";		
	}
	public static String getInputText(String inType,String inInputName,String inInputId,String inInputValue){
		return "<input type='"+inType+"' name='"+inInputName+"' id='"+inInputId+"' value='"+inInputValue+"' />";		
	}
	public static String getInputText(String inType,String inInputName,String inInputValue){
		return "<input type='"+inType+"' name='"+inInputName+"' id='"+inInputName+"' value='"+inInputValue+"' />";		
	}
	public static String getInputSubmitButton(String inTableName){
		return "<button type='submit' >${sessionScope."+Symbol.getStringFirstLowerCase(inTableName)+"==null?'添加':'修改'}</button>";
	}
	public static String getInputResetButton(){
		return "&nbsp;&nbsp;<button type='reset' >重置</button>";
	}
	public static String getInputGoBackButton(){
		return "&nbsp;&nbsp;<button type='button' onclick='history.go(-1);' >返回</button>";
	}
	/**
	 * @return <input type="hidden" name="method" id="method" value="${param.@param inPrimarykey==null?'add':'edit'}" />
	 */
	public static String getInputFormMethodHidden(String inTableName,int inType){
		return Symbol.enterSymbol+" <input type=\"hidden\" name=\"method\" id=\"method\" value=\"${"+(inType==0?"param":"sessionScope")+"."+Symbol.getStringFirstLowerCase(inTableName)+"==null?'add':'edit'}\" />"+Symbol.enterSymbol;
	}
	/**
	 * 
	 *<select name='inSelectName' id='inSelectName' >
     *<c:forEach items="inListName" var="inCVname" varStatus="status">
     *<option value='inSVvalue' ${inSVvalue==inSelectValue?' selected ':''}>inSVname</option>
     *</c:forEach>
     *</select>
	 * @return
	 */
	public static String getSelect(String inSelectName,String inListName,String inCVname,String inSVvalue,String inSVname,String inSelectValue){
		return "<select name='"+inSelectName+"' id='"+inSelectName+"' >"+JstlProcess.getCforeach(inListName, inCVname, Symbol.enterSymbol+"<option value='"+inSVvalue+"' "+JstlProcess.getElExpressValue(inSVvalue+"=="+inSelectValue+"?' selected ':''")+">"+JstlProcess.getElExpressValue(inSVname)+"</option>")+Symbol.enterSymbol+"</select>";
		
	}
	/***********************************TableProcess start*************************************/
	
	public static String getTable(String inTableContent){
		return Symbol.enterSymbol+"<table>"+inTableContent+"</table>"+Symbol.enterSymbol;
	}
	public static String getTableThead(String inTableTheadContent){
		return Symbol.enterSymbol+"<thead>"+inTableTheadContent+"</thead>"+Symbol.enterSymbol;
	}
	public static String getTableTbody(String inTableTbodyContent){
		return Symbol.enterSymbol+"<tbody>"+inTableTbodyContent+"</tbody>"+Symbol.enterSymbol;
	}
	public static String getTableTr(String inTrValue){
		return  Symbol.enterSymbol+"<tr>"+inTrValue+Symbol.enterSymbol+"</tr>";
	}
	public static String getTableTd(String inTdValue){
		return Symbol.enterSymbol+Symbol.getSpaceString(4)+"<td>"+inTdValue+"</td>";
	}
	public static String getTableTd(String inTdValue,int inColSpan){
		return Symbol.enterSymbol+Symbol.getSpaceString(4)+"<td colspan='"+inColSpan+"' >"+inTdValue+"</td>";
	}
	public static String getTableTh(String inThValue){
		return Symbol.enterSymbol+Symbol.getSpaceString(4)+"<th>"+inThValue+"</th>";
	}	
	public static String getTableTh(String inThValue,int inColSpan){
		return Symbol.enterSymbol+Symbol.getSpaceString(4)+"<th colspan='"+inColSpan+"' >"+inThValue+"</th>";
	}
	public static String getAddOrEditTd(String inColumnNickName,String inColumnName){
		return getTableTr(getTableTd(inColumnNickName)+getTableTd(getInputText(inColumnName)));
	}
	public static String getJspListTableHeadTr(String[] viewArray,HttpServletRequest request){
		String tempHeadString="";
		for(int i=0;i<viewArray.length;i++)
			tempHeadString+=getTableTd(request.getParameter(viewArray[i]));
		return tempHeadString;
	}
	public static String getJspListTableHeadInfo(String inTableName,String[] viewArray,HttpServletRequest request,int inType){
		String tempHeadString="";
		for(int i=0;i<viewArray.length;i++)
			tempHeadString+=getTableTr(getTableTd(request.getParameter(viewArray[i].split("#")[0]))+getTableTd("<input type='text' name='"+Symbol.getStringFirstLowerCase(viewArray[i].split("#")[0])+"' id='"+Symbol.getStringFirstLowerCase(viewArray[i].split("#")[0])+"' value='${"+(inType==0?"":"sessionScope.")+Symbol.getStringFirstLowerCase(inTableName)+"."+Symbol.getStringFirstLowerCase(viewArray[i].split("#")[0])+" }' />"));
		return tempHeadString;
	}
	public static String getJspListTableBodyInfo(String inTableName,String[] viewArray){
		String viewColumn="";
		for(int i=0;i<viewArray.length;i++)
			viewColumn+=getTableTd(JstlProcess.getElExpressValue(Symbol.getStringFirstLowerCase(inTableName)+"."+Symbol.getStringFirstLowerCase(viewArray[i])));
		return JstlProcess.getCforeach(Symbol.getStringFirstLowerCase(inTableName)+"List", Symbol.getStringFirstLowerCase(inTableName), HtmlProcess.getTableTr(viewColumn));
	}
	public static String getJspListTableBodyInfo(String inTableName,String[] viewArray,String inModifyOrDelButton){
		String viewColumn="";
		for(int i=0;i<viewArray.length;i++)
			viewColumn+=getTableTd(JstlProcess.getElExpressValue(Symbol.getStringFirstLowerCase(inTableName)+"."+Symbol.getStringFirstLowerCase(viewArray[i])));
		return JstlProcess.getCforeach("${sessionScope."+Symbol.getStringFirstLowerCase(inTableName)+"List==null?'':sessionScope."+Symbol.getStringFirstLowerCase(inTableName)+"List}", Symbol.getStringFirstLowerCase(inTableName), HtmlProcess.getTableTr(viewColumn+inModifyOrDelButton));
	}
	public static String getJspModifyAhrefTag(String inPath,String inContent){
		return "<a href='"+inPath+"'>"+inContent+"</a>";
	}
	public static String getJspModifyAonclickTag(String inPath,String inContent){
		return "<a href=javascript:void(0);'' onclick='"+inPath+"'>"+inContent+"</a>";
	}
	public static void main(String[] args) {
	}
}
